package com.foreveross.dao.imp;

import java.util.List;

import org.springframework.stereotype.Component;

import com.foreveross.common.Constants;
import com.foreveross.common.SQLUtil;
import com.foreveross.dao.PayCostFavorableInfoDAO;
import com.foreveross.vo.PayCostFavorableInfo;


@Component("payCostFavorableInfoDAO")
public class PayCostFavorableInfoDAOImp extends SQLUtil implements PayCostFavorableInfoDAO {

	@Override
	public List<PayCostFavorableInfo> findPayCostFavorableInfoList(
			String weixinId,String orderId,String userId,String houseId,String tenementId,String businessId,String hrFavorableId,
			String payType,String payStatus,String startOrderTime,String endOrderTime
			) throws Exception {
		StringBuffer sqlStr = new StringBuffer();
		sqlStr.append("select model from PayCostFavorableInfo model ");
		sqlStr.append(" where 1=1  ");
		if(null != orderId && !"".equals(orderId)){
			sqlStr.append(" and model.orderInfo = '"+orderId+"' ");
		}
		if(null!=weixinId && !"".equals(weixinId)){
			sqlStr.append(" and model.houseUser in (select b.id from HouseUser b where b.wechatId ='" + weixinId + "' and b.authenticationStatus = '"+Constants.AUTHENTICATIONSTATUS_SUCCESS+"' )");
		}
		if(null!=houseId && !"".equals(houseId)){
			sqlStr.append(" and model.hrHouses ='" + houseId + "'");
		}
		if(null!=tenementId && !"".equals(tenementId)){
			sqlStr.append(" and model.tenement ='" + tenementId + "'");
		}
		if(null!=businessId && !"".equals(businessId)){
			sqlStr.append(" and model.hrBusiness ='" + businessId + "'");
		}
		if(null!=hrFavorableId && !"".equals(hrFavorableId)){
			sqlStr.append(" and model.hrFavorable ='" + hrFavorableId + "'");
		}
		if(null!=payType && !"".equals(payType)){
			sqlStr.append(" and model.payType ='" + payType + "'");
		}
		if(null!=payStatus && !"".equals(payStatus)){
			sqlStr.append(" and model.payStatus ='" + payStatus + "'");
		}
		if(null!=startOrderTime && !"".equals(startOrderTime)){
			sqlStr.append(" and model.chargeTime >='" + startOrderTime + "'");
		}
		if(null!=endOrderTime && !"".equals(endOrderTime)){
			sqlStr.append(" and model.chargeTime <='" + endOrderTime + "'");
		}
		if(null!=userId && !"".equals(userId)){
			this.addAuthorityStr(sqlStr, userId,  "hrHouses");
		}
		sqlStr.append(" order by model.chargeTime desc");
		return (List<PayCostFavorableInfo>) findObjectAll(sqlStr.toString());
	}


}
